import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../service/http.service';
import { HttpRouterService } from '../../service/http-router.service';
import { StorageService } from '../../service/storage.service';
import { Product } from '../product.model'
@Component({
  selector: 'app-product-details',
  templateUrl: './product-details.component.html',
  styleUrls: ['./product-details.component.less']
})
export class ProductDetailsComponent implements OnInit {
  public flags = {
    hot:"热门",
    fenqi:"现金分期",
    card:"还信用卡",
    sesame:"芝麻信用",
    real:"实名认证"
  }
  public productId = "";
  public product: Product = new Product();
  constructor(
    private _http:HttpService,
    private _storage: StorageService,
    private _httpRouter:HttpRouterService
  ) { }

  ngOnInit() {
    this.productId = this._storage.getSession("productId");
    this.getProductDetails(this.productId)
  }

  getProductDetails(productId){
    this._http.get(this._httpRouter.getProductDetails+"?id="+productId).then(res => {
      if(res.code == 1){
        res.data.flag = res.data.flag.split(",");
        this.product = res.data;
      }
      console.log(res.data);
    });
  }
  setOrder(pid,outerurl){
    let user = this._storage.getSessionObject("customer");
    let param = "pid="+pid+"&uid="+user.id;
    this._http.post(this._httpRouter.setOrder,param).then(res => {
      window.location.href = outerurl;
    });
  }
  apply(){
    alert("申请成功！");
  }
}
